I need help! C programming

Kinja'd!!! "Bandit" (2bandit)
01/21/2015 at 13:08 • Filed to: None

Kinja'd!!!0 Kinja'd!!! 13

I keep getting an error "error: expected expression before ':' token" in the line marked below and I don't know what is wrong. Neither does my TA haha.

#include

#define PI: 3.1416 //sets constant pi

int main (void)

{

//Local Declarations

float radius;

float volume;

float length;

float number;

float total_volume;

//Statements

//makes user input hotdog data

printf("\nEnter the length of the hot dog: ");

scanf("%f",&length);

printf("\nEnter the radius of the hot dog: ");

scanf("%f",&radius);

printf("\nEnter the number of hot dogs: ");

scanf("%f",&number);

// prints the required values

printf("\nHot dog length: %10.2f ", length);

printf("\nHot dog radius: %10.2f ", radius);

volume = ( PI * radius * radius * length ) + ( ( 4 / 3 ) * PI * radius * radius * radius ); //ERROR

printf("\nVolume(cc) of one hotdog is: %10.2f", volume);

total_volume = volume * number;

printf("\nTotal volume(cc) of hotdogs is: %10.2f", total_volume);

return (0);


DISCUSSION (13)


Kinja'd!!! crowmolly > Bandit
01/21/2015 at 13:12

Kinja'd!!!8

#define PI: 3.1416 //sets constant pi

Don't need the colon.

Should be like

#define AGE 10


Kinja'd!!! RamblinRover Luxury-Yacht > Bandit
01/21/2015 at 13:12

Kinja'd!!!0

Should your whole equation for volume be parenthetical, perhaps? As you've got it now, you're asking for it to add two expressions and make a variable all on one line without forcing it to add the expressions first, and I don't know if C likes that.


Kinja'd!!! Bandit > crowmolly
01/21/2015 at 13:13

Kinja'd!!!1

You are seriously the greatest


Kinja'd!!! RamblinRover Luxury-Yacht > crowmolly
01/21/2015 at 13:13

Kinja'd!!!0

That makes more sense than what I was guessing, but I don't have background in C.


Kinja'd!!! Lekker > crowmolly
01/21/2015 at 13:15

Kinja'd!!!0

beat me to it, nice :D


Kinja'd!!! Tareim - V8 powered > crowmolly
01/21/2015 at 13:15

Kinja'd!!!0

good catch on that, been awhile since I had done some C and was too focused on that one line :D


Kinja'd!!! davesaddiction @ opposite-lock.com > Bandit
01/21/2015 at 13:17

Kinja'd!!!0

T A

These are a few of my favorite things...


Kinja'd!!! Racescort666 > Bandit
01/21/2015 at 13:19

Kinja'd!!!0

Why is pi not a pre-defined value?


Kinja'd!!! crowmolly > RamblinRover Luxury-Yacht
01/21/2015 at 13:21

Kinja'd!!!0

The C compiler should be able to handle that, as the RH of the equation has to evaluate before it does the assignment statement. If you break it up it's really just for human readability.


Kinja'd!!! RamblinRover Luxury-Yacht > crowmolly
01/21/2015 at 13:23

Kinja'd!!!0

Most of my background was doing things in MATLAB and similar idiocy, so I tend to expect innocuous things like that to give compilers hissy fits.


Kinja'd!!! this is not matt farah's foxbodymiata > crowmolly
01/21/2015 at 13:25

Kinja'd!!!1

Oppo over all!

Who needs stack overflow.


Kinja'd!!! BlurpleToyotaDishwasher > Racescort666
01/21/2015 at 13:53

Kinja'd!!!0

Why would it be? In some circumstances you would want it to be to different precisions, so it makes more sense to leave it up to people to define.

edit: oh wait, you mean "why not use the math header defines for it?" ?


Kinja'd!!! orcim > Bandit
01/22/2015 at 02:59

Kinja'd!!!1

Greatest? Hrm.. C code.

Maybe, "Seriously the oldest?" (no offense, crowmolly)

*pulls out Kernighan and Ritchie to check*